package com.item.controller;


import com.item.domain.Chapter;
import com.item.service.ChapterPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ChapterPayController {

    @Autowired
    ChapterPayService chapterPayService;

    @PostMapping(value = "/chapterPay/{limit}/{page}")
    public List<Chapter> chapterPay(
            @PathVariable(value = "limit", required = false) int limit,
            @PathVariable(value = "page", required = false) int page,
            @RequestBody(required = false) Chapter chapter) {
        List<Chapter> chapters = chapterPayService.findAll(limit, page, chapter);

        for (Chapter pay : chapters) {
            System.out.println(pay.getTitle());
        }
        return chapters;
    }

    @PostMapping(value = "/chapterPay/add")
    public Integer chapterPayAdd(@RequestBody Chapter chapter) {

        int i = chapterPayService.add(chapter);
        return i;
    }

    @PutMapping(value = "/chapterPay/update")
    public Integer chapterPayUpdate(@RequestBody Chapter chapter) {

        int i = chapterPayService.update(chapter);
        return i;
    }

    @DeleteMapping(value = "/chapterPay/{id}")
    public Integer chapterPayDelete(@PathVariable(value = "id") int id) {

        int i = chapterPayService.delete(id);
        return i;
    }

}
